using GammaJul.ReSharper.GammaXaml.Highlightings.CSharp;
using JetBrains.Annotations;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Daemon;
using JetBrains.ReSharper.Daemon.Specific.NamingConsistencyCheck;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.Tree;

[assembly: RegisterConfigurableSeverity(
	MismatchedDpNameHighlighting.SeverityId,
	null,
	HighlightingGroupIds.CodeSmell,
	MismatchedDpNameHighlighting.Description,
	MismatchedDpNameHighlighting.Description,
	Severity.WARNING,
	false)]

namespace GammaJul.ReSharper.GammaXaml.Highlightings.CSharp {

	/// <summary>
	/// An highlighting that represents a mismatch between the field name and its registered property name.
	/// </summary>
	[ConfigurableSeverityHighlighting(SeverityId, CSharpProjectFileType.Name, OverlapResolve = OverlapResolveKind.WARNING)]
	public class MismatchedDpNameHighlighting : InconsistentNamingWarning, IHighlighting {
		internal const string SeverityId = "Dp.MismatchedDpName";
		internal const string Description = "Dependency property name doesn't match its field name.";

		private readonly IField _dpField;
		private readonly string _dpName;
		private readonly IArgument _nameArgument;

		/// <summary>
		/// Gets the field representing the dependency property declaration.
		/// </summary>
		[NotNull]
		public IField DpField {
			get { return _dpField; }
		}

		/// <summary>
		/// Gets the name of the dependency property.
		/// </summary>
		[NotNull]
		public string DpName {
			get { return _dpName; }
		}

		/// <summary>
		/// Gets the argument representing the name of the property in a DependencyProperty.Register()-like initialization.
		/// </summary>
		[NotNull]
		public IArgument NameArgument {
			get { return _nameArgument; }
		}

		public new string ToolTip {
			get { return Description; }
		}

		public new string ErrorStripeToolTip {
			get { return Description; }
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="MismatchedDpNameHighlighting"/> class.
		/// </summary>
		/// <param name="dpField">The field representing the dependency property declaration.</param>
		/// <param name="dpName"> </param>
		/// <param name="expectedFieldName">The name of the dependency property.</param>
		/// <param name="nameArgument">The argument representing the name of the property in a DependencyProperty.Register()-like initialization.</param>
		/// <param name="sourceFile">The source file containing the element to rename.</param>
		public MismatchedDpNameHighlighting([NotNull] IField dpField, [NotNull] string expectedFieldName, [NotNull] string dpName, [NotNull] IArgument nameArgument, [NotNull] IPsiSourceFile sourceFile)
			: base(dpField, dpField.ShortName, null, expectedFieldName, sourceFile) {
			_dpField = dpField;
			_dpName = dpName;
			_nameArgument = nameArgument;
		}
	}

}
